﻿{$header}
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">已发货订单 [ <a href="__URL__">返回列表</a> ] 
    <a class="btn btn-primary" href="__URL__/invoice/oid/{$vo.id}"> <i class="icon-shopping-cart  icon-white"></i>配货单</a>
        <a class="btn btn-primary" href="__URL__/shipping/oid/{$vo.id}"> <i class="icon-plane  icon-white"></i>快递单</a>
  </h3>
<div id="result" class="result none"></div>
<table cellpadding=3 cellspacing=3 >
    <form class="form-horizontal well" method='post' id="form1" action="__URL__/update/">

    <tr><td colspan="4" class="heading h4 alert alert-info"> {$vo.sale_no} ({$vo.order_source_id|getModelName='Order_source'} | {$vo.mall_no})   &nbsp; &nbsp;&nbsp;&nbsp; 配货状态：{$vo.prepare_status|getConfigVal='prepare_status'} </td> </tr>
    <tr>
        <td>订单状态：</td><td>{$vo.order_status|getConfigVal='orderStatus'} --  <eq name="vo.status" value="1" >审核通过<else/>未审核</eq>

        <td>下单时间：</td><td>{$vo.create_time|toDate}</td>

        </td>
    </tr>
     <tr> <td>收货人：</td><td>{$vo.shipping_name}</td>
         <td>手机</td><td> {$vo.mobile}</td>
    </tr>
    <tr>
       <td>地址：</td><td>{$vo.address}</td>
        <td>电话</td><td> {$vo.phone}</td>
    </tr>
    <tr>
        <td>客户留言：</td><td colspan="3">{$vo.customer_msg}</td>
     </tr>
    <tr>
        <td>快递公司：</td><td>{:modList('Logicompany',$vo['logicompany_id'],'span2','logicompany_id','sort desc' )}</td>
        <td>单号：</td><td> <input type="text" name="logino" value="{$vo.logino}">  发货时间: {$vo.shipping_time|toDate}
        </td>
    </tr>

<tr>
    <td>备注</td>
    <td colspan="3"><textarea name="remark" rows="2" class="span8">{$vo.remark}</textarea> </td>
</tr>

<tr>
	<td></td>
	<td class="center" width="300">
        <input type="hidden" value="{$vo.id}" name="id">
	<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<button type="reset" onclick="javascript:history.back()" class="btn btn-primary offset1"><i class="icon-arrow-left icon-white"></i> 返回</button>
	</td>
</tr>
</form>
<tr><td colspan="3" class="heading h4 alert alert-info">商品明细--{$vo.sale_no} ( 总数量：{$vo.sum_number})</td>         
    </tr>
    <tr>
        <td colspan="4">
            <table class="table table-bordered table-striped" id="sale_detail">
                <tr>
                    <th>序号</th><th>配货状态</th><th>规格</th><th>商品名称</th> <th>仓位</th><th>数量</th><th class="span1">单位</th><th>小计</th><th>缺货登记</th>
                </tr>
                <php>$sale_details = M('Sale_detail')->where('sale_no ="'.$vo['sale_no'].'"')->order('id')->findAll(); </php>
                <volist name="sale_details" id="sa">
                <form action="__URL__/out_stock_log" method="post">
                    <tr>
                        <td>{$key+1}
                        <input type="hidden" name="sale_detail_id" value="{$sa.id}">
                        <input type="hidden" name="sale_id" value="{$vo.id}">
                         </td>
			<td>{$sa.prepare_status|getConfigVal='prepare_status'}</td>
                        <td>
                           {$sa.product_id|printGoodsOption}
                           <eq name="sa.is_gift" value="1"><img src="__PUBLIC__/Images/gift.jpg" width="40" height="40"> </eq>
                           <?php $is_virtual = getModelName($sa['product_id'],'Product','is_virtual'); ?>
                           <eq name="is_virtual" value="1">[虚拟商品]</eq>  
                        </td>
                        <td class="span6">{$sa.product_id|getModelName='Product'}</td>
                        <td>{$sa.location}</td>
                        <td>{$sa.number} </td>
                        <td>{$sa.product_id|getProductUnit}</td>
                        <td>{$sa.total}</td>
                        <td>
                    </tr>
                    </form>
                </volist>
            </table>
        </td>
    </tr>
</table>
<?php 
$action_history = M('Action')->where('model ="Sale" and obj_id ='.$vo['id'] )->order('id desc')->findAll(); 
$sale_detail_ids = M('Sale_detail')->where('sale_id ='.$vo['id'])->field('id')->findAll(); //not include delete sale_detail
$detail_history = array();
$delete_sale_detail_ids = array() ;


$delete_sale_details = D('ActionHistoryView')->where('model = "Sale_detail" and field ="delete"')->field('id,diff')->findAll();
$this_del_details = array();
foreach ($delete_sale_details as $dkey => $dvalue) {
    $detail = unserialize($dvalue['diff']);
    if($detail[0]['sale_id'] == $vo['id'] ){ //得到对应的删除ACTION
       $delete_sale_detail_ids[$dkey]['id'] = $detail[0]['id']; //存入已经删除的sale_detail_id
    }
}
//the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended
$sale_detail_ids = array_merge($sale_detail_ids, $delete_sale_detail_ids );
foreach ($sale_detail_ids as $k => $v) {

    $tmp_detail = M('Action')->where('model ="Sale_detail" and obj_id ='.$v['id'] )->order('id desc')->findAll();
    
    if(is_array($tmp_detail))
       $detail_history = array_merge($detail_history,$tmp_detail );
    
}

?>
<table class="table table-bordered table-striped">
    <tr><td colspan="7" class="heading h4 alert alert-info">操作日志 </td></tr>
<tr><th>序号</th><th>操作人</th><th>ip</th><th>操作时间</th><th>操作概要</th> <th>动作</th> <th>详细</th> </tr>
<volist name="action_history" id="ah"> 
    <tr>
        <td>{$ah.id}</td>
        <td>{$ah.user_id|getModelName='User'}</td>
        <td>{$ah.ip}</td>
        <td>{$ah.create_time|toDate}</td>
        <td>{$ah.comment}</td>
        <td>{$ah.action}</td>
        <?php 
        $historys = M('History')->where('action_id ='.$ah['id'])->findAll();
         ?>
        <td>
            <div class="changes" id="changeBox3" style="display: block; ">{:A('Action')->printChanges('Sale',$historys)}</div>
        </td>
    </tr>
</volist>

<volist name="detail_history" id="dh"> 
    <tr>
        <td>{$dh.id}</td>
        <td>{$dh.user_id|getModelName='User'}</td>
        <td>{$dh.ip}</td>
        <td>{$dh.create_time|toDate}</td>
        <td>{$dh.comment}</td>
        <td>{$dh.action}</td>
        <?php 
        $historys = M('History')->where('action_id ='.$dh['id'])->findAll();
         ?>
        <td>
            <div class="changes" id="changeBox3" style="display: block; ">
                <eq name="dh.action" value="删除">
                    {:dump(unserialize($historys[0]['diff']))}
                    <else/>
                    {:A('Action')->printChanges('Sale_detail',$historys)}
                </eq>
            </div>
        </td>
    </tr>
</volist>

</table>

</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
